<%@ page import="java.util.*,com.actimind.actitime.Keys,com.actimind.actitime.reports.*,
                 org.apache.struts.util.ResponseUtils,
                 com.actimind.actitime.util.StringUtils"%>
<%@ page errorPage="/error.jsp" %>
<%@ taglib uri="/WEB-INF/at.tld" prefix="at" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<at:CheckLoggedIn/>
<bean:define id="report" name="report" type="ReportInfo"/>
<bean:define id="form" name="StaffOutputReportForm" type="StaffOutputReportForm"/>

<html>
<head>
    <title><bean:write name="title-prefix" scope="application"/> <%= StaffOutputReportAction.getReportTitle(request) %></title>
    <link rel="stylesheet" href="../css/at.css" type="text/css">
    <script language="JavaScript" src="../js/at.js"></script>

</head>
<body bgcolor="#ffffff" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">

<jsp:include page="../top.jsp" flush="false">
    <jsp:param name="pageSection" value="reports"/>
    <jsp:param name="pageAction" value="staffoutput"/>
</jsp:include>

<table width="770" align="center" cellspacing="0" cellpadding="4" border="0">
<tr>
    <td class="pagetitle" valign="top"> <%= StaffOutputReportAction.getReportTitle(request) %></td>
</tr>
<tr><td><at:errors/></td></tr>
<tr>
    <td><html:link page="/reports/staffoutput.do">
        &lt;&lt; Change report parameters
        </html:link>
    </td>
</tr>
<tr>
    <td class="text" colspan="<%=2+report.getColumns().size()%>">
        <br>
        <span class="formblocktitle">Report parameters:</span> 
        <bean:write name="report" property="parametersString"/>
    </td>
</tr>
</table>

<table bgcolor="#CCCCCC" width="770" align="center" cellspacing="0" cellpadding="0" border="0">
<tr>
<td bgcolor="#CCCCCC">
<table width="100%" align="center" cellspacing="1" cellpadding="4" border="0">
<tr>
    <td nowrap valign="center" class="listtblcolheader" width="242"><img src="../img/pixel.gif" width=1 height=10/><br><bean:write name="StaffOutputReportForm" property="title"/><br><img src="../img/pixel.gif" width=1 height=10/></td>
    <td nowrap width="5%" class="listtblcolheader" align="center">Spent</td>
    <% for(Iterator it = report.getColumns().iterator(); it.hasNext(); ) {
         ReportColumn col = (ReportColumn) it.next();
    %>
    <td nowrap width="5%" class="reportcolheader" align="center"><%=ResponseUtils.filter(col.getName())%></td>
    <% } %>
</tr>
<tr>
    <td class="reportrow0" align="right">Total:</td>
    <td class="reportrow0num" align="center"><%=ResponseUtils.filter(report.getRootEntry().getTotalValue().getFormattedValue())%></td>
    <% for(Iterator it = report.getColumns().iterator(); it.hasNext(); ) {
         ReportColumn col = (ReportColumn) it.next();
    %>
    <td class="reportrow0num" align="center">
    <%
        ReportValue rootValue = report.getRootEntry().getValue(col.getKey());
        out.println(ResponseUtils.filter(rootValue.getFormattedValue()));
    %>
    </td>
    <% } %>
</tr>
<%!
    public void printReport(JspWriter out, HttpServletResponse response, ReportInfo report, ReportEntry entry, int level, List styles)
        throws java.io.IOException
    {
        if(level > styles.size())
            throw new IllegalArgumentException("Report level may not be more then 3");
        String styleClass = "reportrow" + styles.get(level);
        out.print("<tr>");
        out.print("<td class='" + styleClass + "' style='text-align: left;'>");
        out.print("<div style='padding-left: " + (level * 30) + "px;'>");
        out.print(ResponseUtils.filter(entry.getName()));
        out.print("</div></td>");
        out.print("<td class='" + styleClass + "num' align='center'>");
        out.print(ResponseUtils.filter(entry.getTotalValue().getFormattedValue()));
        out.print("</td>");
        String commentsURL = "rep_comments.do?identity=" +  entry.getIdentity();
        for(Iterator it = report.getColumns().iterator(); it.hasNext();)
        {
            ReportColumn col = (ReportColumn) it.next();
            out.print("<td class='" + styleClass + "num' align='center'>");
            ReportValue reportValue = entry.getValue(col.getKey());
            if(reportValue.hasComments()) {
                String readyCommentsURL = response.encodeURL(commentsURL + "&userId=" + col.getKey());
                out.print("<a title='Click to view comments' href='javascript:void(0);' onclick='popup(\"" + readyCommentsURL + "\", \"popupViewComments\", 750, 300);return false;'>");
            }
            out.print(ResponseUtils.filter(reportValue.getFormattedValue()));
            if(reportValue.hasComments()) out.print("</a>");
            out.print("</td>");
        }
        out.println("</tr>");
        for(Iterator it = entry.getChildEntries().iterator(); it.hasNext(); )
        {
            ReportEntry childEntry = (ReportEntry)it.next();
            printReport(out, response, report, childEntry, level + 1, styles);
        }
    }
%>
<%
    for(Iterator it = report.getRootEntry().getChildEntries().iterator(); it.hasNext(); )
    {
        ReportEntry childEntry = (ReportEntry)it.next();
        List styles = new ArrayList();
        styles.add(new Integer(1));
        if(form.getSecondGrouping() != StaffOutputReportForm.REPORT_GROUPING_NONE)
            styles.add(new Integer(2));
        if(form.isShowTasks())
            styles.add(new Integer(3));
        printReport(out, response, report, childEntry, 0, styles);
    }
%>
</table>
</td>
</tr>
</table><br><br>
</body>
</html>
